var rootPath = getRootPath();
$(function() {
	var E = window.wangEditor;
	var editor = new E('#editor');
	// 设置编辑区域高度为 500px
	editor.config.height = 450;
	editor.config.placeholder = '积分规则设置从这开始>>>';

	// 配置 server 接口地址
	// editor.config.uploadImgServer = '/upload-img';

	editor.config.showLinkImg = false;// 隐藏 网络上传图片
	editor.config.uploadImgShowBase64 = true;

	editor.config.menus = [ 'head', 'bold', 'fontSize', 'fontName', 'italic',
			'underline', 'strikeThrough', 'indent', 'lineHeight', 'foreColor',
			'backColor', 'link', 'list', 'justify', 'quote',
			// 'emoticon',
			'image',
			// 'video',
			'table',
			// 'code',
			'splitLine', 'undo', 'redo', ];

	editor.create();
	
	 $.ajax({
			url: rootPath + '/integralRule/getIntegralRule',
			type: 'POST',
			contentType: 'application/json;charset=UTF-8',
			success: res=> {
				if(res.returnCode == "0000" && res.returnObject != undefined && res.returnObject.irContent != undefined){
					editor.txt.html(res.returnObject.irContent);	
				}
			},
			error:res=>{
				layer.alert("系统出错了~");
			}
	 });
	
	
	
	$("#commit").click(function() {
		var content = editor.txt.html();
		if(content == undefined || $.trim(content) == '' ){
			layer.msg("当前文本不包含任务内容");
			return;
		}
		$.ajax({
				url: rootPath + '/integralRule/saveIntegralRule',
				type: 'POST',
				contentType: 'application/json;charset=UTF-8',
				dataType : 'json',
				data : JSON.stringify({"irContent" : content }),
				success: res=> {
					layer.msg("保存成功",{icon:1,time:1000},function() { });
				},
				error:res=>{
					layer.alert("系统出错了~");
				}
		 });
		
		
	});
})